package com.endurance.controller;

import com.endurance.clients.DeptsClients;
import com.endurance.entity.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @ProjectName: spring-cloud-hoxton-parent
 * @Package: com.endurance.controller
 * @ClassName: EmpController
 * @Description:
 * @Author: sunlin
 * @CreateDate: 2024/02/05 09:00
 * @Version: 1.0
 */

@RestController
@RequestMapping("/emp")
public class EmpController {

    @Value("${server.port}")
    private String port;

    @Autowired
    private DeptsClients deptsClients;

    @GetMapping("invokeDept")
    public String emp() {
        System.out.println("员工接口");
        String dept = deptsClients.dept();
        System.out.println(dept);
        return "emp-ok:" + port;
    }


    @GetMapping("getReturnList")
    public String getReturnList() {
        List<Dept> returnList = deptsClients.getReturnList("部门");
        returnList.stream().forEach(System.out::println);
        return "getReturnList";
    }

    @GetMapping("getParamsRestful")
    public String getParamsRestful() {
        Dept dept = deptsClients.getParamsRestful(3);
        System.out.println(dept);
        return "getParamsRestful";
    }

    @GetMapping("getPost")
    public String getPost() {
        deptsClients.getPost(new Dept(1, "111", new Date()));
        return "getPost";
    }


    @GetMapping("getByName")
    public String getByName() {
        List<Dept> returnList = deptsClients.getByName("sl");
        returnList.stream().forEach(System.out::println);
        return "getByName";
    }

}
